//配置axios
// 导入
import axios from 'axios';
import qs from 'qs';
// axios.defaults.baseURL = 'http://47.93.206.13:5588';
// axios.defaults.baseURL = 'http://47.97.1.39:8001';
axios.defaults.baseURL = 'http://47.103.192.197:8001';
//sessionStorage.clear();
//sessionStorage.removeItem("token");
// axios.defaults.headers.common["Authorization"] = sessionStorage.getItem('token');
// JWT 身份认证
// 请求拦截器
axios.interceptors.request.use(config => {
  // Do something before request is sent
  // console.log(config, '-----');
  config.headers = {
    //accept:'',
    ...config.headers,
    Authorization: sessionStorage.getItem('token')
  }
  if (config.method == 'post' && config.url !== "/user/login") {
    config.data = qs.stringify(config.data);
  }
  return config;
}, error => {
  // Do something with request error
  return Promise.reject(error);
});
// 响应拦截器
axios.interceptors.response.use(response => {
  // Do something before response is sent
  // console.log(response, '++++');
  let res = {
    ...response,
    data: response.data.data,
    status: response.data.status,
    statusText: response.data.message,
    timestamp: response.data.timestamp
  }
  return res;
}, error => {
  // Do something with response error
  return Promise.reject(error);
});




// 导出
export default axios;

